<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <title>后台小类型页面</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="/after/css/bootstrap.min.css?v=3.4.0" rel="stylesheet">
    <link href="/after/css/font-awesome.min.css?v=4.3.0" rel="stylesheet">
    <link href="/after/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
    <link href="/after/css/animate.min.css" rel="stylesheet">
    <link href="/after/css/style.min.css?v=3.0.0" rel="stylesheet">

    <link href="/after/js/laypage/skin/laypage.css" rel="stylesheet">
    <!--引用vue的js-->
    <script src="/after/js/vue/vue.min.js"></script>
    <!--分页插件-->
    <script src="/after/js/laypage/laypage.js" charset="utf-8"></script>
    <script src="/after/js/layer/layer.js" charset="utf-8"></script>


    <script src="/after/js/jquery-2.1.1.min.js" type="text/javascript"></script>
    <script src="/after/js/bootstrap.min.js?v=3.4.0" type="text/javascript"></script>
    <script type="text/javascript" src="/after/js/Globals.js"></script>
    <script type="text/javascript" src="/after/js/websocket.js"></script>
    <script type="text/javascript" src="/after/js/vue/vue.min.js"></script>
    <script src="/after/js/layer/layer.js" charset="utf-8"></script>

<style>
    #editable t{background-color: white;}
</style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight" id="app">
    <br>
    <br>
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <h2>活动管理
                    <div class="ibox-tools">
                        <a href="javascript:;" class="btn btn-primary btn-xs" id="addActive">创建新活动</a>
                    </div>
                </h2>
                <div class="ibox-title" id="bt">
                    <input type="button"  class="btn btn-sm btn-primary" value="搜索" onclick="getActivePageList();"/>
                    <input type="text" id="type" name="name" style="text-align: left"/><br>
                </div>
                <div class="ibox-title"></div>
                <div class="ibox-content">
                    <table class="table table-striped table-bordered table-hover" id="editable">
                        <thead>
                        <tr>
                            <th>编号</th>
                            <th>活动内容</th>
                            <th>活动名称</th>
                            <th>图片</th>
                            <th>开始时间</th>
                            <th>结束时间</th>
                            <th>折扣</th>
                            <th>针对类型</th>
                            <th style="text-align: center">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr class="active" v-for="(item,index) in result">
                            <td>{{item.id}}</td>
                            <td>{{item.name}}</td>
                            <td>{{item.content}}</td>
                            <td>{{item.picture}}</td>
                            <td>{{new Date(item.createTime).toLocaleString()}}</td>
                            <td>{{new Date(item.endTime).toLocaleString()}}</td>
                            <td>{{item.discount}}</td>
                            <td>{{item.btype.type}}</td>
                            <td>
                                <a href="#" @click="editEvent(item.id)" class="btn btn-white btn-sm"><i class="fa fa-folder"></i>编辑</a>
                                <a href="#" @click="delEvent(item.id)" class="btn btn-white btn-sm"><i class="fa fa-pencil"></i>删除</a>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    <div id="pagenav"></div>
                </div>
            </div>
        </div>
    </div>
</div>


<script>
    var app = new Vue({
        el : '#app',
        data : {
            result : []
        }
    });
    var getActivePageList = function(curr) {
        $.ajax({
            url:"/active/findAll.do",
            type:"post",
            dataType:"JSON",
            data : {
                pageNum:curr || 1,
                pageSize:3,
                name:$("#type").val()
            },
            error:function () {
                alert("错误");
            },
            success:function (msg) {
                app.result=msg.page;

                laypage({
                    cont : 'pagenav', //容器。值支持id名、原生dom对象，jquery对象,
                    pages : msg.totalPage, //总页数
                    skin:'#FFFFFF',
                    first : '首页',
                    last : '尾页',
                    curr : curr || 1, //当前页
                    jump : function(obj, first) { //触发分页后的回调
                        if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                            getActivePageList(obj.curr);
                        }
                    }
                });
            }
        });
    }
    getActivePageList();

    //添加功能
    $("#addActive").on("click",function(){
        layer.open({
            type:2,
            title:'添加活动',
            fix:false,
            maxmin:true,
            shadeClose:true,
            area:['1100px','800px'],
            content:'/backstage/HJHAddActive.ftl',
            end:function(){
                getActivePageList();
            }
        })
    })

    //添加删除功能
    var delEvent = function (id) {
        layer.confirm('确定删除？', {
            btn: ['是', '否']
        }, function () {
            //是
            $.ajax({
                type: 'GET',
                dataType: 'json',
                url: '/active/delActive.do',
                data: {
                    id: id
                },
                success: function (msg) {
                    if(msg){
                        getActivePageList();
                        layer.msg('成功删除' + id, {icon: 6});
                    }
                }
            });
            //否
        }, function () {

        });
    }

    //编辑数据_查
    var editEvent = function (id) {
        layer.open({
            type: 2,
            title: '编辑活动',
            fix: false,
            maxmin: true,
            shadeClose: true,
            area:['1100px','800px'],
//            content: '/active/findActive.do?id='+id,
            content: '/backstage/HJHUpdateActive.ftl?id='+id,
            end: function () {
                getActivePageList();
            }
        });
    }

</script>
</body>
</html>